//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __NAMEDOBJ_H__
#define __NAMEDOBJ_H__

#include <elasys_server.h>
#include "linknode.h"
#include <aura.h>

#define NAMED_HS_SLOTS 16

class NamedObjectFactory;

class NamedObject: public DLinkNode
{
public:
    virtual PInterface GetObject() = 0;
    virtual oid_t     GetOid()    = 0;
    virtual Int32   GetType()   = 0;
    virtual Boolean CompareName(WString name) = 0;

public:
    STATIC ECode S_Initialize();
    STATIC void  S_Destroy();

public:
    STATIC ECode S_CreateObject(
        /* [in] */ NamedObjectFactory * pFactory,
        /* [out] */ NamedObject ** ppNamedObj,
        /* [out] */ Boolean * pbAlreadyExisted);

    STATIC ECode S_ResolveObject(
        /* [in] */ NamedObjectFactory * pFactory,
        /* [in] */ oid_t oid,
        /* [out] */ NamedObject ** ppNamedObj);

    STATIC ECode S_DestroyObject(
        /* [in] */ NamedObjectFactory * pFactory,
        /* [in] */ oid_t oid);

private:
    STATIC ECode _S_GetObject(
        /* [in] */ WString name,
        /* [out] */ NamedObject ** ppObject);

    STATIC ECode _S_AddObject(
        /* [in] */ WString name,
        /* [in]  */ NamedObject * pNamedObj);

    STATIC ECode _S_DeleteObject(
        /* [in] */ WString name);

public:
    STATIC DLinkNode s_namedHashList[NAMED_HS_SLOTS];
    STATIC PVoid     s_hListLock;
};

class NamedObjectFactory
{
public:
    virtual WString GetName() = 0;
    virtual ObjectType GetType() = 0;

    virtual ECode CreateNamedObject(
            /* [out] */ NamedObject ** ppNamedObj,
            /* [out] */ Boolean * pbAlreadyExisted) = 0;

    virtual ECode ResolveNamedObject(
            /* [in]  */ oid_t oid,
            /* [out] */ NamedObject ** ppNamedObj) = 0;

    virtual ECode DestroyNamedObject(
            /* [in]  */ oid_t oid) = 0;
};

#endif //__NAMEDOBJ_H__
